pp108 : Business Object

Business Object

 

A Business Object represents the XML data object that can be read, created and modified. It can be a block of data retrieved from backend (such as records from a specific database), or can be data retrieved from the Process Platform LDAP.

A Business Object encapsulates all the attributes of one block of data into one object. It is managed in the web browser, and can be regarded as the defining point of data available or stored in the model.

The following can be considered as business objects:

  • All data records retrieved from a database.
  • All blocks of entry retrieved from LDAP.

In Cordys, a business object is defined as the transact-able data object available in thetuple/oldnode of a response that is returned from the backend.

Consider the following response, returned by the GetEmployeesObject method:

<GetEmployeesObjectResponse xmlns="...">
 <tuple>
   <old>
       <Employees>
          <EmployeeID>1</EmployeeID>
       </Employees>
   </old>
 </tuple>
 <tuple>
   <old>
      <Employees>
         <EmployeeID>2</EmployeeID>
      </Employees>
   </old>
 </tuple>
</ GetEmployeesObjectResponse>

Here, Employees denotes the business object (equivalent to a 'record' in database).

The XPath to this Business Object may be defined as

sXPath = "nwd:old/nwd:Employees"

where, 'nwd' is the prefix set for the namespace.

Each business object of the transact-able data consists of a set of business elements, which are the individual data elements inside a business object. It contributes to the transactional state of the object itself. In the above code,EmployeeIDis a business element of theEmployeesbusiness object. Business elements can be retrieved by executing an XPath reference on the Business Object.

Business Object States

A service-oriented architecture platform such as Process Platform, manages multiple states of business objects by maintaining their old and new values. To enable this, business objects are enclosed in old or new tags. These tags denotes the state of a business object as follows:

  • Old: Contains the original business object retrieved from the server.
  • New: Contains the modified or newly created business object.

Depending on the interactions that you make with the object, the state of the business object changes. The following are the various states of a business object:

  1. READ: Data is retrieved from the server. This is represented by having a tuple/old and business object.
  2. UPDATE: Data is modified in the client (through user interactions). Business object is enclosed in tuple/old and tuple/new tags. The new tag holds the modified business object, while the old contains the old state of the data when it was retrieved.
  3. INSERT: Data is newly created in the client (for example, when you click the Insert button). The business object is enclosed in a tuple/new tag.
  4. DELETE: Data is marked for deletion in the client (for example, when you select records for deletion). Data is present inside a tuple/old tag, and contains a special attribute (sync_id) to indicate that the data object is ready to be deleted from the server.

Non-transactional data

The non-transactional data of a business object is not part of atuple/oldprotocol. This data can be defined in business object scenarios, but the state of such data cannot be maintained in atuple/oldortuple/newprotocol to track the changes done to the data.

Consider the following:

<items>
    <item>
        <itemID>10</itemID>
    </item>
    <item>
        <itemID>11</itemID>
    </item>
</items>

In the above sample, every item is a business object, and everyitemIDdenotes the business element inside the business object.

Current Context

Each business element can have only one value inside a business object. In the above example of Employees, there is only oneEmployeeIDinside a business object. If multiple values of the same business element is present inside a business object, and causes the value to repeat, the business element can be accessed based on the Current Context of a data object.

Setting References

A business object is automatically identified for transactional data as the block of data available inside thetuple/oldortuple/new. However, business object has to be explicitly defined for non-transactional data using the Reference property available on every control. Similarly, references to the business elements are evaluated from the business object.

Business objects and business elements can be set through the Reference property available on all controls.

Retrieving business object

A business object can be retrieved from multiple controls. The following are some possibilities:

Business object

Syntax

Description

HTML Controls

controlId.getBusinessObject()

Returns Business Object.

Select box options

option.businessObject

Returns the business object node related to the select box's option.

Table rows

row.businessObject

Returns the business object node of the current row in a table.

Model

model.getActiveBusinessObject()

Returns the current active business object on the model. This denotes the selected row in table, or the data shown in Groupbox.

The getBusinessObject() method returns an object with the following methods:

Method

Description

getTuple()

Returns the tuple of the current business object.

getOld()

Returns the old business object from the data. Old object refers to the original data from the server that is not yet modified and is in the READ state. For a newly created business object (in client or server), this value is null.

getNew()

Returns the new business object from the data. A new object is available for the business objects that are modified in the client application or those that are associated with the INSERT stage.

getCurrent()

Returns a business object depending on its current state in the client. A business object can be associated with the following states:

  • Old: For unmodified data associated with the server or for data marked for deletion.
  • New: For updated data that is ready for synchronization or that is newly added in the client or server.

getState()

Returns the status of the business object. The status can be:

  • read: The business object is read from the backend.
  • update: The business object is ready for synchronization with the backend.
  • insert: The business object is ready to be inserted to the backend.
  • delete: The business object is ready to be deleted from the backend.
  • " ": No data is available for the business object.

Example

The code below retrieves the current value of EmployeeID field from the business object:

var bo = employeeid.getBusinessObject();
var employeeidValue = cordys.selectXMLNode(bo.getCurrent(),".//*[local-name()='EmployeeID']");

The following code reads the business object from a table's row and reads the field EmployeeID from there:

var businessObject = table1.getRows()[2].businessObject;
var employeeidValue = cordys.selectXMLNode(businessObject,".//*[local-name()='EmployeeID']");

Applies to

HTML Controls

Related reference

Model
Transactional and Non-transactional Data
Current Context
getRows()
xforms-onactivebusinessobject
getActiveBusinessObject()